﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class Kho_say_DB
    {
        public static DataTable SelectKhoSay()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblQLKho_Say", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblQLKho_Say", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void InsertKhoSay(KhoSay newItem)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemCTKhoSay", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemCTKhoSay", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaKhoSay", newItem.Makhosay);
                command.Parameters.AddWithValue("@NgayThang", newItem.NgayThang);
                command.Parameters.AddWithValue("@MaLo", newItem.Malo);
                command.Parameters.AddWithValue("@MaNhom", newItem.Manhom);
                command.Parameters.AddWithValue("@MaNX", newItem.Manx);
                command.Parameters.AddWithValue("@MaTP", newItem.Matp);
                command.Parameters.AddWithValue("@DienGiai", newItem.Diengiai);
                command.Parameters.AddWithValue("@KLNhap_Say", newItem.KLnhap_say);
                command.Parameters.AddWithValue("@KLVao_Lo", newItem.KLvao_lo);
                command.Parameters.AddWithValue("@KLThu_Hoi", newItem.KLthu_hoi);
                command.Parameters.AddWithValue("@Xuat_Kho", newItem.Xuat_kho);
                command.ExecuteNonQuery();

            }
        }
        public static void UpdateKhoSay(string oldMaKhoSay, KhoSay newItem)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapnhatCTKhoSay", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapnhatCTKhoSay", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaKhoSay", oldMaKhoSay);
                command.Parameters.AddWithValue("@NgayThang", newItem.NgayThang);
                command.Parameters.AddWithValue("@MaLo", newItem.Malo);
                command.Parameters.AddWithValue("@MaNhom", newItem.Manhom);
                command.Parameters.AddWithValue("@MaNX", newItem.Manx);
                command.Parameters.AddWithValue("@MaTP", newItem.Matp);
                command.Parameters.AddWithValue("@DienGiai", newItem.Diengiai);
                command.Parameters.AddWithValue("@KLNhap_Say", newItem.KLnhap_say);
                command.Parameters.AddWithValue("@KLVao_Lo", newItem.KLvao_lo);
                command.Parameters.AddWithValue("@KLThu_Hoi", newItem.KLthu_hoi);
                command.Parameters.AddWithValue("@Xuat_Kho", newItem.Xuat_kho);
                command.ExecuteNonQuery();
            }
        }
        public static void DeleteKhoSay(string oldMaKhoSay)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaCTKhoSay", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaCTKhoSay", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaKhoSay", oldMaKhoSay);
                command.ExecuteNonQuery();

            }
        }
    }
}
